home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-10-25 | 2.1 KB | 86 lines | [TEXT/KAHL] |
- // cheatpreffile.c
- // deals with making a preferences file in the System folder
-
- #include <Files.h>
- #include "cheatpreffile.h"
-
- #define preffilename "\pCheat Prefs"
- #define preffilecreator 'chit'
- #define preffiletype 'pref'
-
- static OSErr DoCreatePrefsFile(short VRefNum, long DirID)
- {
- return HCreate(VRefNum, DirID, preffilename, preffilecreator, preffiletype);
- }
-
-
- static int IsFindFolder(void)
- {
- OSErr Result;
- long Feature;
-
- Result = Gestalt(gestaltFindFolderAttr, &Feature);
- if (Result == noErr)
- return ((Feature & (1 << gestaltFindFolderPresent)) != 0);
- // return (btst(Feature, gestaltFindFolderPresent));
- return Result;
- }
-
-
- int DoReadPrefs(Ptr p, long length)
- {
- short VRefNum;
- long DirID, ThePrefs;
- short fref, ret;
- OSErr result;
-
- if (IsFindFolder())
- result = FindFolder(kOnSystemDisk, kPreferencesFolderType,
- kDontCreateFolder, &VRefNum, &DirID);
- else
- result = -1;
- if (result) { // set directory to current directory, tough luck sonny
- VRefNum = 0;
- DirID = 0;
- }
- result = HOpen(VRefNum, DirID, preffilename, fsCurPerm, &fref);
- if (result) // no existing file forget it
- return false;
- result = FSRead(fref, &length, p); // get info
- result = FSClose(fref);
- fref = 0; // so we don't wipe out any disks (see THINK ref)
- return length;
- }
-
-
- void DoSavePrefs(Ptr p, long length)
- {
- short VRefNum;
- long DirID, ThePrefs;
- short fref;
- OSErr result;
-
- if (IsFindFolder())
- result = FindFolder(kOnSystemDisk, kPreferencesFolderType,
- kDontCreateFolder, &VRefNum, &DirID);
- else
- result = -1;
- if (result) { // set directory to current directory, tough luck sonny
- VRefNum = 0;
- DirID = 0;
- }
- result = HOpen(VRefNum, DirID, preffilename, fsCurPerm, &fref);
- if (result) { // no existing file, make a new one
- result = DoCreatePrefsFile(VRefNum, DirID);
- if (result)
- return; // canna do it
- result = HOpen(VRefNum, DirID, preffilename, fsCurPerm, &fref);
- if (result)
- return;
- }
- result = FSWrite(fref, &length, p); // get info
- if (!result)
- result = SetEOF(fref, length); // just in case
- result = FSClose(fref);
- fref = 0; // so we don't wipe out any disks (see THINK ref)
- }